package com.peng.security.distributed.uaa.service;

import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @program: distributed-security
 * @description:
 * @author: Mr.Wang
 * @create: 2020-01-02 22:12
 **/
@Service
public class SpringUserDetailService implements UserDetailsService {


    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        String encode = bCryptPasswordEncoder.encode("123");

        if("zhangsan".equals(s)) {
            UserDetails userDetails = User.withUsername(s).password(encode).authorities("p1").build();
            return userDetails;
        }
        return null;
    }
}
